<template>
  <div>
    <!-- 表单 -->
    <el-form :label-position="labelPosition" size="small" :model="form" :inline="true" label-width="70px">
      <el-form-item label="姓 名" style="font-weight:bold;">
        <el-input v-model="form.userName" placeholder="请输入姓名" style="width:150px;" clearable></el-input>
      </el-form-item>
      <el-form-item label="性 别" style="font-weight:bold;">
        <el-select v-model="form.sex" placeholder="请选择性别" style="width:150px;" clearable>
          <el-option label="男" value="1"></el-option>
          <el-option label="女" value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学 号" style="font-weight:bold;">
        <el-input v-model="form.userNum" placeholder="请输入学号" style="width:150px;" clearable></el-input>
      </el-form-item>
      <el-form-item label="年 级" style="font-weight:bold;">
        <el-input v-model="form.grade" placeholder="(如2020级)" style="width:150px;" clearable></el-input>
      </el-form-item>
      <el-form-item label="电 话" style="font-weight:bold;">
        <el-input v-model="form.userPhone" placeholder="请输入手机号" style="width:150px;" clearable></el-input>
      </el-form-item>
      <el-form-item label="状 态" style="font-weight:bold;">
        <el-select v-model="form.state" placeholder="请选择状态" style="width:150px;" clearable>
          <el-option label="在读" value="0"></el-option>
          <el-option label="已毕业" value="1"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="校 区" style="font-weight:bold;">
        <el-select v-model="form.campusId" placeholder="请选择校区" style="width:150px;" clearable>
          <el-option v-for="item in CampusName" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="部门 :">
        <el-select v-model="form.region" placeholder="请选择部门" style="width:300px">
        </el-select>
      </el-form-item> -->
      <el-form-item label="院 系" style="font-weight:bold;">
        <el-select :disabled="clientRole == 1 || clientRole == 2" v-model="form.collegeId" placeholder="请选择院系"
          style="width:150px;" clearable>
          <el-option v-for="item in CollegeName" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="辅导员" style="font-weight:bold;">
        <el-select v-model="form.adminName" placeholder="请选择" style="width:150px;" clearable>
          <el-option v-for="item in teachers" :key="item.id" :label="item.name" :value="item.name"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="学生类型" style="font-weight:bold;">
        <el-select v-model="form.type" placeholder="请选择学生类型" style="width:150px;" clearable>
          <el-option label="本科生" value="0"></el-option>
          <el-option label="硕士生" value="1"></el-option>
          <el-option label="博士生" value="2"></el-option>
          <el-option label="留学生" value="3"></el-option>
          <el-option label="交换生" value="4"></el-option>
          <el-option label="专科生" value="5"></el-option>
        </el-select>
      </el-form-item>
      <el-button style="height:30px;" size="small" class="search_button" type="primary" icon="el-icon-search"
        @click="getDataList">查询</el-button>
      <el-button style="height:30px;" size="small" class="reset_button" icon="el-icon-refresh"
        @click="reset">重置</el-button>
    </el-form>
    <!-- 表单 -->



    <!-- 按钮 -->
    <el-row class="btnBox">
      <div class="handleBox" v-show="clientRole != 1 && clientRole != 2">
        <el-button style="height:30px;" size="small" type="primary" @click="dialog_newly = true"
          icon="el-icon-folder-add">新增</el-button>
        <!-- <el-button type="danger" class="delete_button" icon="el-icon-delete">删除</el-button> -->
        <el-button style="height:30px;" size="small" type="warning" icon="el-icon-download" @click="downLoadExcelStudent"
          plain>下载学生信息模板</el-button>
        <el-button style="height:30px;" size="small" type="success" plain icon="el-icon-download"
          @click="exportStudent">导出学生信息</el-button>
        <el-upload style="margin-left:10px;" action="#" :before-upload="beforeUpload" ref="newupload"
          :http-request="uploadHttpRequest" :limit="3" :file-list="fileList" :show-file-list="false">
          <el-button style="height:30px;" size="small" type="primary" plain icon="el-icon-upload2">导入学生信息</el-button>
        </el-upload>
        <el-upload style="margin-left:10px;" action="#" :before-upload="beforeUpload" ref="newupload"
          :http-request="uploadAdmin" :limit="3" :file-list="fileList" :show-file-list="false">
          <el-button style="height:30px;" size="small" type="primary" plain icon="el-icon-upload2">导入学生辅导员</el-button>
        </el-upload>
      </div>
      <div class="searchBox">

      </div>
    </el-row>
    <!-- 按钮 -->

    <el-divider></el-divider>

    <!-- 表格 -->
    <el-table size="medium" ref="multipleTable" :data="tableData" border style="width: 100%"
      @selection-change="handleSelectionChange">
      <!-- <el-table-column prop="campusName" label="校区" align="center"></el-table-column> -->
      <el-table-column prop="collegeName" label="院系" align="center"></el-table-column>
      <!-- <el-table-column prop="buildName" label="楼宇" align="center"></el-table-column> -->
      <el-table-column prop="userNumber" label="学号" align="center" width="140"></el-table-column>
      <el-table-column prop="userName" label="姓名" align="center"></el-table-column>
      <el-table-column prop="sex" label="性别" align="center">
        <template slot-scope="scope">
          <span v-if="(scope.row.sex == 1)">男</span>
          <span v-if="(scope.row.sex == 0)">女</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="roomNum" label="宿舍" align="center"></el-table-column>  -->
      <el-table-column prop="grade" label="年级" align="center"></el-table-column>
      <el-table-column prop="scholasticYear" label="学年制" align="center"></el-table-column>
      <el-table-column prop="type" label="学生类型" align="center">
        <template slot-scope="scope">
          <span v-if="(scope.row.type == 0)">本科生</span>
          <span v-if="(scope.row.type == 1)">硕士生</span>
          <span v-if="(scope.row.type == 2)">博士生</span>
          <span v-if="(scope.row.type == 3)">留学生</span>
          <span v-if="(scope.row.type == 4)">交换生</span>
          <span v-if="(scope.row.type == 5)">专科生</span>
        </template>
      </el-table-column>
      <el-table-column prop="className" label="专业/班级" align="center" min-width="100"></el-table-column>
      <el-table-column prop="state" label="状态" align="center">
        <template slot-scope="scope">
          <span v-if="(scope.row.state == 1)">已毕业</span>
          <span v-if="(scope.row.state == 0)">在读</span>
        </template>
      </el-table-column>
      <el-table-column prop="adminName" label="辅导员" align="center"></el-table-column>

      <el-table-column prop="userPhone" label="常用电话" align="center" width="170">
        <template slot-scope="scope">
          <span>{{ scope.row.userPhone }}</span>
          <el-button v-if="scope.row.userPhone" icon="el-icon-scissors" size="mini" type="text"
            @click="removePhone({ id: scope.row.id })">解绑</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="standbyPhone" label="备用电话" align="center" width="110">
      </el-table-column>
      <!-- <el-table-column prop="handle" label="解绑手机号" align="center" width="100">
        <template slot-scope="scope">
          <el-button v-if="scope.row.userPhone" icon="el-icon-scissors" size="mini" type="text"
            @click="removePhone({ id: scope.row.id })">解绑</el-button>
        </template>
      </el-table-column> -->
      <el-table-column prop="handle" label="操作" align="center" width="200">
        <template slot-scope="scope">
          <!-- <el-button v-if="scope.row.liveState == 0" icon="el-icon-refresh" size="mini" type="text"
            @click="roomChange(scope.row)">调整宿舍</el-button>
          <el-button v-if="scope.row.liveState != 0" icon="el-icon-office-building" size="mini" type="text"
            @click="roomIn(scope.row)">办理入住</el-button>
          <el-button v-if="scope.row.liveState == 0" icon="el-icon-delete" size="mini" type="text"
            @click="roomOut(scope.row)">退宿</el-button> -->
          <el-button icon="el-icon-edit" size="mini" type="text" @click="updateStudent(scope.row)">修改信息</el-button>
          <el-button size="mini" type="text" plain @click="deleteStudent({ id: scope.row.id })">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格 -->

    <el-pagination class="pagination" background layout="total, sizes, prev, pager, next, jumper" :total="total"
      :page-size="10" :page-sizes="[10, 20, 30, 40]" @current-change="handleCurrentChange"
      @size-change="handleSizeChange"></el-pagination>

    <!-- @next-click='next' @prev-click='prev' -->

    <!-- 添加学生弹窗 -->
    <el-dialog title="添加学生信息" :visible.sync="dialog_newly">
      <el-form :model="formNew" :label-position="labelPosition" label-width="90px" style="margin-left:6%;" :inline="true">
        <el-form-item label="姓名 :" :rules="[{ required: true, message: '姓名不能为空' }]" prop="name">
          <el-input v-model="formNew.name" style="width:220px;" placeholder="请输入姓名" clearable></el-input>
        </el-form-item>
        <!-- <el-form-item label="电话 :">
          <el-input v-model="formNew.userPhone" style="width:220px;" placeholder="请输入电话"></el-input>
        </el-form-item> -->
        <el-form-item label="学号 :" :rules="[{ required: true, message: '学号不能为空' }]" prop="userNum">
          <el-input v-model="formNew.userNum" style="width:220px;" placeholder="请输入学号" clearable></el-input>
        </el-form-item>
        <!-- <el-form-item label="密码 :">
          <el-input v-model="formNew.password" style="width:220px;" placeholder="请输入密码"></el-input>
        </el-form-item> -->
        <el-form-item label="性别 :" :rules="[{ required: true, message: '性别不能为空' }]" prop="sex">
          <el-select v-model="formNew.sex" placeholder="请选择性别" style="width:220px;" clearable>
            <el-option label="男" value="1"></el-option>
            <el-option label="女" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份证号 :" :rules="[{ required: true, message: '身份证号不能为空' }]" prop="idLast">
          <el-input v-model="formNew.idLast" style="width:220px;" placeholder="请输入身份证号后六位" clearable></el-input>
        </el-form-item>
        <el-form-item label="年级 :" :rules="[{ required: true, message: '年级不能为空' }]" prop="grade">
          <el-input v-model="formNew.grade" style="width:220px;" placeholder="请输入年级" clearable></el-input>
        </el-form-item>
        <el-form-item label="学年制 :" :rules="[{ required: true, message: '学年制不能为空' }]" prop="scholasticYear">
          <el-input v-model="formNew.scholasticYear" style="width:220px;" placeholder="请输入学年制(如:4年)" clearable></el-input>
        </el-form-item>
        <!-- <el-form-item label="校区 :" :rules="[{ required: true, message: '校区不能为空' }]" prop="campusId">
          <el-select v-model="formNew.campusId" placeholder="请选择校区" style="width:220px" clearable>
            <el-option v-for="item in CampusName" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="院系 :" :rules="[{ required: true, message: '院系不能为空' }]" prop="collegeId">
          <el-select v-model="formNew.collegeId" placeholder="请选择院系" style="width:220px;" clearable>
            <el-option v-for="item in CollegeName" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生类型 :" :rules="[{ required: true, message: '学生类型不能为空' }]" prop="type">
          <el-select v-model="formNew.type" placeholder="请选择学生类型" style="width:220px;" clearable>
            <el-option label="本科生" value="0"></el-option>
            <el-option label="硕士生" value="1"></el-option>
            <el-option label="博士生" value="2"></el-option>
            <el-option label="留学生" value="3"></el-option>
            <el-option label="交换生" value="4"></el-option>
            <el-option label="专科生" value="5"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="专业/班级 :">
          <el-select v-model="formNew.className" placeholder="请选择(专业/班级)" style="width:220px;" clearable>
            <el-option v-for="item in ClassName" :key="item.id" :label="item.classes" :value="item.classes"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="辅导员 :" style="font-weight:bold;">
          <el-select v-model="formNew.adminName" placeholder="请选择" style="width:220px;" clearable>
            <el-option v-for="item in teachers" :key="item.id" :label="item.name" :value="item.name"></el-option>
          </el-select>
        </el-form-item>


        <!-- <el-form-item label="状态 :">
          <el-select v-model="formNew.state" placeholder="请选择状态" style="width:200px;">
            <el-option label="启用" value="0"></el-option>
            <el-option label="禁用" value="1"></el-option>
          </el-select>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialog_newly = false">取 消</el-button>
        <el-button type="primary" @click="addStudent" class="dialogbutton">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 添加学生弹窗 -->

    <!-- 修改学生弹窗 -->
    <el-dialog title="修改学生信息" :visible.sync="dialog_change" width="50%">
      <el-form :model="formChange" :label-position="labelPosition" label-width="90px" style="margin-left:6%;"
        :inline="true">
        <el-form-item label="姓名 :">
          <el-input :disabled="clientRole == 1 || clientRole == 2" v-model="formChange.userName" style="width:220px;"
            placeholder="请输入姓名" clearable></el-input>
        </el-form-item>
        <el-form-item label="电话 :">
          <el-input v-model="formChange.userPhone" style="width:220px;" placeholder="请输入电话" clearable></el-input>
        </el-form-item>
        <el-form-item label="学号 :">
          <el-input :disabled="clientRole == 1 || clientRole == 2" v-model="formChange.userNum" style="width:220px;"
            placeholder="请输入学号" clearable></el-input>
        </el-form-item>
        <!-- <el-form-item label="密码 :">
          <el-input v-model="formChange.password" style="width:220px;" placeholder="请输入密码" clearable></el-input>
        </el-form-item> -->
        <el-form-item label="性别 :">
          <el-select v-model="formChange.sex" placeholder="请选择性别" style="width:220px;" clearable>
            <el-option label="男" value="1"></el-option>
            <el-option label="女" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份证号 :">
          <el-input v-model="formChange.idLast" style="width:220px;" placeholder="请输入身份证号后六位" clearable></el-input>
        </el-form-item>
        <el-form-item label="年级 :">
          <el-input v-model="formChange.grade" style="width:220px;" placeholder="请输入年级" clearable></el-input>
        </el-form-item>
        <el-form-item label="学年制 :">
          <el-input v-model="formChange.scholasticYear" style="width:220px;" placeholder="请输入学年制" clearable></el-input>
        </el-form-item>
        <el-form-item label="院系 :">
          <el-select :disabled="clientRole == 1 || clientRole == 2" v-model="formChange.collegeId" placeholder="请选择院系"
            style="width:220px;" clearable>
            <el-option v-for="item in CollegeName" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生类型 :">
          <el-select v-model="formChange.type" placeholder="请选择学生类型" style="width:220px;" clearable>
            <el-option label="本科生" value="0"></el-option>
            <el-option label="硕士生" value="1"></el-option>
            <el-option label="博士生" value="2"></el-option>
            <el-option label="留学生" value="3"></el-option>
            <el-option label="交换生" value="4"></el-option>
            <el-option label="专科生" value="5"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="专业/班级 :">
          <el-select v-model="formChange.className" placeholder="请选择(专业/班级)" style="width:220px;" clearable>
            <el-option v-for="item in ClassName" :key="item.id" :label="item.label" :value="item.classes"></el-option>
          </el-select>
        </el-form-item>

        <!-- <el-form-item label="辅导员 :">
          <el-input v-model="formChange.adminName" style="width:220px;" placeholder="请输入" clearable></el-input>
        </el-form-item> -->

        <el-form-item label="辅导员 :" style="font-weight:bold;">
          <el-select v-model="formChange.adminName" placeholder="请选择" style="width:220px;" clearable>
            <el-option v-for="item in teachers" :key="item.id" :label="item.name" :value="item.name"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="状态 :">
          <el-select v-model="formChange.state" placeholder="请选择状态" style="width:220px;" clearable>
            <el-option label="在读" value="0"></el-option>
            <el-option label="已毕业" value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialog_change = false">取 消</el-button>
        <el-button type="primary" @click="updateStudentConfirm" class="dialogbutton">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 修改学生弹窗 -->




  </div>
</template>

<script>
import { getClassName, addStudent, removePhone, getStudent, updateStudent, deleteStudent, uploadStudent, exportStudent, downLoadExcelStudent, uploadStudentAdmin } from '_api/UserManage/Student/index.js'
import { getCampusName } from '_api/DormManage/Building/index.js'
import { getCollegeName, getTeacher } from '_api/DormManage/College/index.js'
import { getDepartmentName } from '_api/DormManage/Department/index.js'
import {
  getBuildingName,
} from '_api/DormManage/Building/index.js'
import {
  getDormByBuildId
} from '_api/DormManage/Room/index.js'
import {
  getBedListByDorm
} from "_api/DormManage/Bed/index.js"
import { encode } from '@utils/upload/base64.js'

export default {
  data() {
    return {
      clientRole: "",
      campus: "",
      building: "",
      defaultProps: {
        label: "name",
        value: "id",
        children: "children",
        // checkStrictly: true
      },
      buildId: "",
      floor: "",
      dormNum: "",
      labelPosition: "right",
      dialog_newly: false,
      dialog_change: false,
      form: {
        adminName: "",
        campusId: "",
        collegeId: "",
        current: 0,
        field: "",
        order: "",
        pageSize: 10,
        sex: "",
        state: "",
        userName: "",
        userNum: "",
        grade: "",
        type: "",
        userPhone: ""
      },
      formNew: {
        // campusId: "",
        collegeId: "",
        grade: "",
        name: "",
        sex: "",
        type: "",
        userNum: "",
        idLast: "",
        scholasticYear: "",
        className: "",
        adminName: ""
      },
      formChange: {
        collegeId: "",
        grade: "",
        id: "",
        // password: "",
        sex: "",
        state: "",
        type: "",
        userName: "",
        userNum: "",
        userPhone: "",
        idLast: "",
        scholasticYear: "",
        className: "",
        adminName: ""
      },
      tableData: [],
      CampusName: [],
      CollegeName: [],
      DepartmentName: [],
      BuildingName: [],
      RoomName: [],
      BedName: [],
      fileList: [],
      ClassName: [],
      timeNow: "",
      total: 0,
      changeRoom: false,
      changeRoomData: {
        studentId: "",
        newBed: "",
        reason: ""
      },
      outRoom: false,
      outRoomData: {
        studentId: "",
        reason: ""
      },
      inRoom: false,
      inRoomData: {
        studentId: "",
        reason: "",
        newBed: "",
      },
      teachers: []
    }
  },
  watch: {
    formNew: {
      // 执行方法
      handler(oldValue, newValue) {
        getClassName({ collegeId: newValue.collegeId }).then(res => {
          if (res.status == 200) {
            res.data.data.forEach(item => {
              item['label'] = item.grade + '-' + item.classes
            })
            this.ClassName = res.data.data
          }
        })
        getTeacher({ collegeId: newValue.collegeId }).then(res => {
          if (res.status == 200) {
            this.teachers = res.data.data
          }
        })
      },
      deep: true, // 深度监听
      // immediate: true  // 第一次改变就执行
    },
    // form: {
    //   // 执行方法
    //   handler(oldValue, newValue) {
    //     getTeacher({ collegeId: newValue.collegeId }).then(res => {
    //       if (res.status == 200) {
    //         this.teachers = res.data.data
    //       }
    //     })
    //   },
    //   deep: true, // 深度监听
    //   // immediate: true  // 第一次改变就执行
    // },
    floor: {
      // 执行方法
      handler(oldValue, newValue) {
        if (oldValue != "") {
          getDormByBuildId({ buildId: this.buildId, floor: this.floor }).then(res => {
            this.RoomName = res.data.data
          })
        }
      },
      deep: true, // 深度监听
    },
    dormNum: {
      // 执行方法
      handler(oldValue, newValue) {
        if (oldValue != "") {
          getDormByBuildId({ buildId: this.buildId, floor: this.floor, dormNum: this.dormNum }).then(res => {
            this.RoomName = res.data.data
          })
        }
      },
      deep: true, // 深度监听
    }
  },
  methods: {
    handleSelectionChange() {
    },
    //重置
    reset() {
      this.form = {
        campusId: "",
        // collegeId: "",
        current: 0,
        field: "",
        order: "",
        pageSize: 10,
        sex: "",
        state: "",
        userName: "",
        userNum: "",
        grade: "",
        type: "",
        userPhone: ""
      }
      this.getCollegeName()
    },
    // 添加学生
    addStudent() {
      if (this.formNew.idLast == "") {
        this.$message("身份证号不能为空")
        return false
      }
      // var data = JSON.parse(JSON.stringify(this.formNew))
      // data.idLast = encode(data.idLast, 'UTF-8')
      addStudent(this.formNew).then(res => {
        if (res.data.success == true) {
          this.dialog_newly = false
          this.$message({
            message: '添加成功!',
            duration: 1000,
            type: 'success',
            onClose: () => {
              this.reset()
            }
          })
        } else {
          this.$message({
            message: res.data.message,
            duration: 1000,
          })
        }
      }).catch(error => {
        // console.log(error.response)
        if (error.response.status != 200) {
          this.$message.info(error.response.data.message)
        }
      })
    },
    // 导入学生信息
    uploadHttpRequest(data) {
      let fd = new FormData()
      fd.append('file', data.file)
      const loading = this.$loading({
        lock: true,
        text: '数据导入中,请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      uploadStudent(fd).then(res => {
        if (res.data.success == true) {
          loading.close();
          this.$message.success("导入成功！")
          this.reset()
        } else {
          loading.close();
          this.$message({
            message: res.data.message,
            duration: 3000
          })
        }
      }).catch(error => {
        loading.close();
        this.$message({
          message: "数据过多,请适当删减！",
          duration: 3000
        })
      })
    },
    // 导入学生辅导员
    uploadAdmin(data) {
      let fd = new FormData()
      fd.append('file', data.file)
      const loading = this.$loading({
        lock: true,
        text: '数据导入中,请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      uploadStudentAdmin(fd).then(res => {
        if (res.data.success == true) {
          loading.close();
          this.$message.success("导入成功！")
          this.reset()
        } else {
          loading.close();
          this.$message({
            message: res.data.message,
            duration: 3000
          })
        }
      }).catch(error => {
        loading.close();
        this.$message({
          message: "数据过多,请适当删减！",
          duration: 3000
        })
      })
    },
    beforeUpload(file) {
      // console.log(file)
      // 校验
      let legalName = ["xlsx", "xls"];
      // 拿到后缀名
      let name = file.name.substring(
        file.name.lastIndexOf(".") + 1,
        file.name.length
      );
      if (legalName.includes(name)) {
        // console.log(legalName.includes(name));
      } else {
        this.$message.info("文件格式不对,仅限xls和xlsx");
        return false;
      }
    },
    //获取当前时间
    getCurrentTime() {
      var _this = this;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
      _this.gettime = yy + '/' + mm + '/' + dd + ' ' + hh + ':' + mf + ':' + ss;
      // console.log(_this.gettime)
      this.timeNow = _this.gettime
    },
    // 下载学生信息模板
    downLoadExcelStudent() {
      downLoadExcelStudent().then(res => {
        // console.log(res, "121212121212")
        const link = document.createElement('a')  //创建a标签
        const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }) //设置文件流
        link.style.display = 'none'// 设置连接
        link.href = URL.createObjectURL(blob)  //将文件流转化为blob地址
        this.getCurrentTime()
        link.download = '学生信息模板_' + this.timeNow
        document.body.appendChild(link) // 模拟点击事件
        link.click()  //设置点击事件
        this.$message.success('下载成功！')
      })
    },
    // 导出学生信息
    exportStudent() {
      exportStudent(this.form).then(res => {
        // console.log(res.data,"121212121")
        const link = document.createElement('a')  //创建a标签
        const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }) //设置文件流
        link.style.display = 'none'// 设置连接
        link.href = URL.createObjectURL(blob)  //将文件流转化为blob地址
        this.getCurrentTime()
        link.download = '学生信息报表_' + this.timeNow
        document.body.appendChild(link) // 模拟点击事件
        link.click()  //设置点击事件
        this.$message.success('导出成功！')
      })
    },
    //修改学生弹窗
    updateStudent(e) {
      this.dialog_change = true
      // this.formChange.collegeName = e.collegeName
      this.CollegeName.forEach(item => {
        if (item.name == e.collegeName) {
          this.formChange.collegeId = item.id
        }
      })
      this.formChange.grade = e.grade
      this.formChange.id = e.id
      this.formChange.sex = e.sex
      this.formChange.userName = e.userName
      this.formChange.userNum = e.userNumber
      this.formChange.userPhone = e.userPhone
      this.formChange.idLast = e.idLast
      this.formChange.adminName = e.adminName
      this.formChange.scholasticYear = e.scholasticYear
      if (e.type != "" || e.type != null) {
        this.formChange.type = e.type.toString()
      }
      if (e.state != "" || e.state != null) {
        this.formChange.state = e.state.toString()
      }
      getClassName({ collegeId: this.formChange.collegeId }).then(res => {
        if (res.data.success == true) {
          res.data.data.forEach(item => {
            item['label'] = item.grade + '-' + item.classes
          })
          this.ClassName = res.data.data
        }
      })
      getTeacher({ collegeId: this.formChange.collegeId }).then(res => {
        if (res.data.success == true) {
          this.teachers = res.data.data
        }
      })
    },
    //修改学生确认
    updateStudentConfirm() {
      var data = JSON.parse(JSON.stringify(this.formChange))
      if (data.idLast) {
        data.idLast = encode(data.idLast, 'UTF-8')
      }
      updateStudent(data).then(res => {
        // console.log(res)
        if (res.status == 200) {
          this.dialog_change = false
          this.$message({
            message: '修改成功!',
            duration: 1000,
            type: 'success',
            onClose: () => {
              this.reset()
            }
          })
        }
      })
    },
    //删除学生
    deleteStudent(e) {
      this.$confirm('此操作将删除该学生, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteStudent(e).then(res => {
          if (res.status == 200) {
            this.$message({
              message: '删除成功!',
              duration: 1000,
              type: 'success',
              onClose: () => {
                this.reset()
              }
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // prev(e) {
    //   //上一页
    //   this.form.current = e-1
    //   this.getStudent()
    // },
    // next(e) {
    //   //下一页
    //   this.form.current = e-1
    //   this.getStudent()
    // },
    handleCurrentChange(e) {
      //当前页
      this.form.current = e
      this.getStudent()
    },
    handleSizeChange(e) {
      this.form.pageSize = e
      this.getStudent()
    },
    // 查询按钮
    getDataList() {
      this.form.current = 0
      this.getStudent()
    },
    //解绑手机
    removePhone(e) {
      this.$confirm('确定解绑该手机吗', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        removePhone(e).then(res => {
          console.log(res)
          if (res.data.success == true) {
            this.$message({
              type: 'success',
              message: '解绑成功！'
            })
            this.reset()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    //学生信息查询
    getStudent() {
      getStudent(this.form).then(res => {
        if (res.data.success == true) {
          res.data.data.list.forEach(item => {
            item.roomNum = item.roomNum + item.bedCode
          })
          this.tableData = res.data.data.list
          this.total = res.data.data.total
        } else {
          this.tableData = res.data.data
          this.total = ""
          this.$message.info(res.data.message)
        }
      }).catch(error => {
        // console.log(error.response.status);
        // if (error.response.status == 401) {
        //   this.$confirm('登录状态过期, 请重新登录!', '提示', {
        //     confirmButtonText: '确定',
        //     // cancelButtonText: '取消',
        //     showCancelButton: false,
        //     type: 'warning'
        //   }).then(() => {
        //     this.$router.push('/login')
        //   }).catch(() => {

        //   })
        // }
      })
    },
    //获取校区名称
    getCampusName() {
      getCampusName().then(res => {
        if (res.status == 200) {
          this.CampusName = res.data.data
        }
      })
    },
    //获取学院名称
    getCollegeName() {
      getCollegeName().then(res => {
        if (res.status == 200) {
          this.CollegeName = res.data.data
          if (window.localStorage.getItem('clientRole') == 1 || window.localStorage.getItem('clientRole') == 2) {
            this.CollegeName.forEach(item => {
              if (item.name == window.localStorage.getItem('collegeName')) {
                this.form.collegeId = item.id
              }
            })
          }
        }
        this.getStudent()
      })
    },
    //获取部门名称
    getDepartmentName() {
      getDepartmentName().then(res => {
        if (res.status == 200) {
          this.DepartmentName = res.data.data
        }
      })
    }

  },
  created() {
    this.clientRole = window.localStorage.getItem('clientRole')
    this.getCollegeName()
  },
};
</script>
<style lang="scss" scoped>
.pagination {
  float: right;
  margin-top: 10px;
}


.btnBox {
  width: 700px;
  display: flex;
  justify-content: space-between;
}

.handleBox {
  display: flex;
  margin-left: 70px;
}

.searchBox {
  display: flex;
  margin-left: 200px;
}

.tag {
  cursor: pointer;
  margin-left: 2px;
  width: 70px;
}

.roomBox {}
</style>
